<template>
  <yx-modal title="编辑保存demo" :visible="visible" @confirm="confirm" @close="close">
    <el-form ref="form" :model="form" label-width="80px" :rules="rules">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>

    </el-form>
  </yx-modal>
</template>

<script>
// import yxModal from '@/components/modal/src/yxModal.vue'
export default {
  name: "SaveDemo",
  components: {},
  data() {
    return {
      visible: false,
      form: {
        name: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
      },
    };
  },
  created(){
    console.log("created......")
  },
  methods: {
    show() {
        console.log('弹出打开了');
      this.visible = true;
    },
    resetForm(formName) {
        this.$nextTick(() => {
          this.$refs[formName].resetFields();
        })
    //   this.$refs[formName].resetFields();
    },
    confirm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.visible = false;
          this.$emit("ok", this.form);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    close(){
        this.visible = false;
        this.resetForm('form');
    }
  },
};
</script>
<style>
</style>